package main

import (
	"bytes"
	"fmt"
)

func main() {
	fmt.Println(comma("1641454878"))
	fmt.Println(commaBuffer("1641454878"))
}

func comma(s string) string {
	i := len(s)
	if i <= 3 {
		return s
	}
	return comma(s[:i-3]) + "," + s[i-3:]
}

func commaBuffer(s string) string {
	var buf bytes.Buffer
	l := len(s) % 3
	for i, v := range s {
		if i != 0 && (i-l)%3 == 0 {
			buf.WriteByte(',')
		}
		fmt.Fprintf(&buf, "%c", v)
	}
	return buf.String()
}
